package com.qifenqian.turbot.module.ui.setting

import android.content.Context
import android.content.Intent
import com.qifenqian.turbot.R
import com.qifenqian.turbot.base.BaseActivity
import com.qifenqian.turbot.module.contract.AccountContract
import com.qifenqian.turbot.module.entity.response.VersionEntity
import com.qifenqian.turbot.module.presenter.AccountPresenter
import com.qifenqian.turbot.util.TurbotUtil
import kotlinx.android.synthetic.main.activity_about.*
import org.jetbrains.anko.toast

class AboutActivity : BaseActivity<AccountPresenter, AccountContract.View>(), AccountContract.View {
    companion object {
        fun startThis(context: Context) {
            val intent = Intent(context, AboutActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun bindLayoutId(): Int {
        return R.layout.activity_about
    }

    override fun bindPresenter(): AccountPresenter? {
        return AccountPresenter(this, this)
    }

    override fun initial() {
        tv_about_version.text = "商户版".plus(TurbotUtil.getCurrentVersion(this))
        mPresenter!!.checkVersion()
    }

    override fun checkVersionResult(isSuccess: Boolean, code: Int, msg: String?, versionEntity: VersionEntity?) {
        if (isSuccess) {
            if (TurbotUtil.getCurrentVersion(this) != versionEntity!!.version) {
                cv_about_version.setTextRight("有新版本")
            } else {
                cv_about_version.setTextRight("当前已是最新版本")
            }
        } else {
            toast(msg!!)
        }
    }
}
